﻿@{
    ViewBag.Title = "sedit";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />      
}

<form id="form1" method="post">
            @Html.Partial("~/Views/Modular/Toolbars.cshtml")
        <div name="Base" title="供应商资料" style="height:100%;overflow:hidden;margin-top:15px;margin-left:20px">
            <table >
                <tr>
                    <td width="80px" height ="50px" align="right">
                        供应商编码：</td>
                    <td width="250px" height ="50px">
                        <input name="FNumber" id="FNumber" class="mini-textbox" style="width:250px;" required="true" value="" TabIndex="1"/>
                    </td>
                    <td width="80px" height ="50px" align="right">
                        &nbsp;&nbsp;联系人：</td>
                    <td width="200px" height ="50px">
                        <input id="FContacts" name="FContacts" class="mini-textbox " style="width:200px;"  TabIndex="4"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="50px" align="right">
                        供应商名称：</td>
                    <td width="250px" height ="50px">
                        <input id="FName" name="FName" class="mini-textbox " style="width:250px;" required="true" TabIndex="2"/>
                    </td>
                    <td width="80px" height ="50px" align="right">
                        联系电话：</td>
                    <td width="200px" height ="50px">
                        <input name="FPhone" id="FPhone" class="mini-textbox" style="width:200px;"  value="" TabIndex="5"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="50px" align="right">
                        &nbsp;&nbsp;地&nbsp;&nbsp;址：</td>
                    <td width="250px" height ="50px">
                        <input name="FAddress" id="FAddress" class="mini-textbox" style="width:250px;"  value="" TabIndex="3"/>
                    </td>
                    <td width="80px" height ="50px" align="right">
                        &nbsp;&nbsp;备&nbsp;&nbsp;注：</td>
                    <td width="200px" height ="50px">
                        <input id="FRemark" name="FRemark" class="mini-textbox " style="width:200px;"  TabIndex="6"/>
                    </td>
                </tr>
            </table>
            <br />
        </div>
    <input name="FItemID" class="mini-hidden" />
</form>

<script>
    function FormShown() {
        mini.parse();
        LoadListData();
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            NewInfo();
        }
        else {
            $.post("GetSupply", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                debugger;
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("FNumber").setEnabled(false);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FNumber").setValue("");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FPhone").setValue("");
        mini.getbyName("FContacts").setValue("");
        mini.getbyName("FAddress").setValue("");
        mini.getbyName("FRemark").setValue("");
        var jsonstr = '{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
        $.post('NewInfo', { json: jsonstr }, function (data) {
            mini.getbyName("FNumber").setValue(data);
        });
    }

    //保存资料
    function SaveInfo() {
        if (mini.getbyName("FNumber").getValue() == '') {
            mini.alert('编码不能为空');
            return;
        }
        if (mini.getbyName("FName").getValue() == '') {
            mini.alert('供应商名称不能为空');
            return;
        }
        mini.getbyName("SaveInfo").setEnabled(false);
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }
        var data = form.getData(true, false);

        var json = mini.encode(data);
        $.post("SaveSupplyInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }


    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");//==
        grid.load({ mjson: json });
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/Supply/SupplyInfo",
            title: "供应商资料", width: 700, height: 280,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Supply/SupplyInfo",
                title: "供应商资料", width: 700, height: 280,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    LoadListData();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除资料
    function removeInfo() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var json = "{'FItemID':'" + row.FItemID + "'}";
                        $.post("RemoveSupplyInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                grid.reload();
                            }
                            else {
                                mini.alert("异常:" + ret.error);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

</script>